/**
 * Created by Administrator on 2017/3/1 0001.
 */
var ratio=window.devicePixelRatio;
var pixiStageW=740;
var pixiStageH=1136;
var renderer=PIXI.autoDetectRenderer(pixiStageW,pixiStageH,{antialias:true,transparent:true,resolution:1});
var stage=new PIXI.Stage(0xFF0000);
var resource;

var div_pixi=document.createElement('div');
document.body.appendChild(div_pixi);
div_pixi.appendChild(renderer.view);

var preload=Preload.create();
preload.init(stage,pixiStageW,pixiStageH);


document.addEventListener('Main_LoadComplete',gameStart);
function gameStart(e) {
    resource=e.detail.resources;
    var game=Game.create();
    stage.addChildAt(game.ui,0);
}

var pd=ParticleDemo.create();


resizeHandler();
window.onresize = resizeHandler;
function resizeHandler() {
    renderer.resize(window.innerWidth, window.innerHeight);
    mode='noBorder';
    switch (mode) {
        case 'exactFit':
            stage.scale.x = window.innerWidth / pixiStageW;
            stage.scale.y = window.innerHeight / pixiStageH;
            break;
        case 'noBorder':
            stage.scale.x = (window.innerHeight / pixiStageH < window.innerWidth / pixiStageW) ? (window.innerWidth / pixiStageW) : (window.innerHeight / pixiStageH);
            stage.scale.y = stage.scale.x;
            break;
        case 'noScale':
            stage.scale.x = 1;
            stage.scale.y = 1;
            break;
        case 'showAll':
            stage.scale.x = (window.innerHeight / pixiStageH < window.innerWidth / pixiStageW) ? (window.innerHeight / pixiStageH) : (window.innerWidth / pixiStageW);
            stage.scale.y = stage.scale.x;
            break;
    }
    stage.x = (window.innerWidth - pixiStageW * stage.scale.x) * .5;
    stage.y = (window.innerHeight - pixiStageH * stage.scale.y) * .5;
};

var globalID;
globalID=requestAnimationFrame(animate);
// cancelAnimationFrame(globalID);
function animate() {
    pd.emitter.update(0.01);
    requestAnimationFrame(animate);
    renderer.render(stage);
}